package com.michale.admin.controller.monitor;

import com.github.pagehelper.PageInfo;
import com.michale.admin.controller.tool.BaseController;
import com.michale.common.annotation.Log;
import com.michale.common.domain.operate.OperateLogEntity;
import com.michale.common.enmus.BusinessType;
import com.michale.common.result.AjaxResult;
import com.michale.common.result.PageResult;
import com.michale.system.service.OperateLogService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Michale
 * @apiNote 操作日志管理
 */
@Api(tags = "登录日志管理")
@RestController
@RequestMapping("monitor/operate")
public class OperateLogController extends BaseController {

    @Resource
    private OperateLogService operateLogService;

    /**
     * 查询操作日志集合
     *
     * @param operateLogEntity 分页查询参数
     * @return 操作日志集合
     */
    @GetMapping("/operateLogList")
    @PreAuthorize("@security.isPermission('monitor:operate:list')")
    public PageResult operateLogList(OperateLogEntity operateLogEntity) {
        startPage();
        List<OperateLogEntity> operateLogList = operateLogService.selectOperateLogList(operateLogEntity);
        PageInfo<OperateLogEntity> pageInfo = new PageInfo<>(operateLogList);
        return pageResult(pageInfo);
    }

    /**
     * 批量删除系统操作日志
     *
     * @param operateLogIds 需要删除的操作日志ID
     * @return 结果
     */
    @DeleteMapping("/deleteOperateLog/{operateLogIds}")
    @Log(title = "删除日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@security.isPermission('monitor:operate:remove')")
    public AjaxResult deleteLoginInfoLog(@PathVariable("operateLogIds") Long[] operateLogIds) {
        return toAjax(operateLogService.deleteOperateLogByIds(operateLogIds));
    }

    /**
     * 清空操作日志记录
     *
     * @return 结果
     */
    @DeleteMapping("/cleanOperateLog")
    @Log(title = "清空日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@security.isPermission('monitor:loginInfo:remove')")
    public AjaxResult cleanOperateLog() {
        operateLogService.cleanOperateLog();
        return success();
    }
}
